package com.hundsun.yr.universal.p2p.presenter.impl;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.data.HSSharedPreferences;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.library.widget.HSToast;
import com.hundsun.yr.universal.p2p.bean.AdSlideBeen;
import com.hundsun.yr.universal.p2p.bean.LoginBeen;
import com.hundsun.yr.universal.p2p.bean.MessageBean;
import com.hundsun.yr.universal.p2p.bean.MessageSettingBean;
import com.hundsun.yr.universal.p2p.bean.MyInvestBeen;
import com.hundsun.yr.universal.p2p.bean.MyLoanListBeen;
import com.hundsun.yr.universal.p2p.bean.PrepayPlanBeen;
import com.hundsun.yr.universal.p2p.bean.ProdTypeBean;
import com.hundsun.yr.universal.p2p.bean.ProductBeen;
import com.hundsun.yr.universal.p2p.bean.RepayPlanBeen;
import com.hundsun.yr.universal.p2p.bean.UserInfo;
import com.hundsun.yr.universal.p2p.config.Config;
import com.hundsun.yr.universal.p2p.config.Constants;
import com.hundsun.yr.universal.p2p.config.Container;
import com.hundsun.yr.universal.p2p.config.TaskConstants;
import com.hundsun.yr.universal.p2p.interactor.base.RequestInteractor;
import com.hundsun.yr.universal.p2p.interactor.impl.StringRequestGetInteractorImpl;
import com.hundsun.yr.universal.p2p.interactor.impl.StringRequestInteractorImpl;
import com.hundsun.yr.universal.p2p.listener.BaseMultiLoadedListener;
import com.hundsun.yr.universal.p2p.presenter.base.RequestPresenter;
import com.hundsun.yr.universal.p2p.utils.AndroidDes3Util;
import com.hundsun.yr.universal.p2p.utils.BaseRequestTool2;
import com.hundsun.yr.universal.p2p.utils.CommTool;
import com.hundsun.yr.universal.p2p.utils.GsonTool;
import com.hundsun.yr.universal.p2p.utils.Logs;
import com.hundsun.yr.universal.p2p.view.base.BaseListView;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import de.greenrobot.event.EventBus;

import static com.hundsun.yr.universal.p2p.utils.BaseRequestTool2.getHearder;


/**
 * @Title: BaseListPresenterImpl.java 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @date 2015-10-27 上午11:18:59 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class BaseListEntityPresenterImpl implements RequestPresenter,BaseMultiLoadedListener<String>,OnClickListener{
	
	private Context mContext = null;
	private BaseListView mBaseView = null;
	/**用户信息sp文件**/
	private HSSharedPreferences sharedPreferences = null;
	private HSSharedPreferences mConfigSP = null;
	/**
	 * post请求
	 */
	private RequestInteractor mInteractor=null;
	/**
	 * get请求
	 */
	private RequestInteractor mInteractorGet=null;
	/**list的key**/
	private String mKey;
	/**任务名**/
	private String mTask_name;
	/**请求地址**/
	private String mUrl;
	/**加载事件**/
	private int mEvent_tag;
	/**参数**/
	private HashMap<String, String> mParams;
	private JSONObject mJParams;
	/**是否刷新**/
	private boolean mIsSwipeRefresh;
	/**响应头**/
	private HashMap<String, String> header;
	private String zwgt_data;


	public BaseListEntityPresenterImpl(Context context,BaseListView baseView,String key) {
		// TODO Auto-generated constructor stub
		if (null == baseView) {
            throw new IllegalArgumentException("Constructor's parameters must not be Null");
        }
		this.mContext=context;
		this.mBaseView=baseView;
		this.mInteractor =new StringRequestInteractorImpl(this);
		this.mInteractorGet =new StringRequestGetInteractorImpl(this);
		this.mKey=key;
		this.sharedPreferences = new HSSharedPreferences(context, Config.SPPath.file_userLoginedInfo);
		this.mConfigSP = new HSSharedPreferences(context, Config.SPPath.file_configInfo);
	}

	/**
	 * 网络请求成功
	 * @param task_name
	 * @param event_tag
	 * @param data
	 * @throws Exception
     */
	@Override
	public void onSuccess(String task_name,int event_tag, String data) throws Exception {
		//网络请求成功，进度条消失
		mBaseView.hideLoading();
		mBaseView.closeProgress();//请求数据成功
		try {
			//对数据进行处理
			AdSlideBeen adSlideBeen = (AdSlideBeen) GsonTool.getInstanceByJson(AdSlideBeen.class, data);
			if (adSlideBeen.code.equals(Constants.REQUESTCODE_100600)){
				sharedPreferences.putBoolean(UserInfo.ISLOGIN, false);
				EventBus.getDefault().post(new EventCenter(Constants.EVENT_DATA_LOGIN_EXPIRED));
			}
			switch (task_name){
				case TaskConstants.TASK_GOODSLIST://查询精选商品
					switch (adSlideBeen.code){
						case Constants.REQUESTCODE_000000:
							try{
								//请求成功，对数据进行解密
								String decode;
								if (sharedPreferences.getBoolean(UserInfo.ISLOGIN)){
									decode = AndroidDes3Util.decode(adSlideBeen.data, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
								} else {
									decode = AndroidDes3Util.decode(adSlideBeen.data, mContext.getString(R.string.default_key), (Date.parse(adSlideBeen.timestamp)+"").substring((Date.parse(adSlideBeen.timestamp)+"").length() - 8,(Date.parse(adSlideBeen.timestamp)+"").length()));
								}

								String[] split = decode.split("\\n");
//								Logs.e("xushunzhen" + split[1]);
								ArrayList<ProductBeen> productBeens = GsonTool.jsonToArrayList(split[1], ProductBeen.class);
								Container.getInstance().setSystemTime(System.currentTimeMillis() + "");
								//对数据进行解析
								if (event_tag==Constants.EVENT_REFRESH_DATA){
									//event_tag为刷新界面
									if (productBeens.size() > 0){
										mBaseView.refreshListData(productBeens);
//										Log.e("refreshListData",productBeens.get(0).add_debt_rate);
									}else {
										mBaseView.refreshListData(null);
										//没有数据显示空页面
										mBaseView.showEmpty(0, mContext.getString(R.string.empty_msg), this);
									}
								} else if (event_tag == Constants.EVENT_LOAD_MORE_DATA){
									if (productBeens.size() > 0){
										mBaseView.addMoreListData(productBeens);
									}else {
										//没有更多
										mBaseView.addMoreListData(productBeens);
									}
								}
								break;
							}catch (Exception e){
								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error) + e.toString()).show();
								e.printStackTrace();
							}
						case Constants.REQUESTCODE_100020:
							mBaseView.onFailure(TaskConstants.TASK_GOODSLIST);
							break;
						case Constants.REQUESTCODE_100010:
							mBaseView.onFailure(TaskConstants.TASK_GOODSLIST);
							break;
						case Constants.REQUESTCODE_100600:
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							mBaseView.onFailure(TaskConstants.TASK_GOODSLIST + "outTime");
							break;
						default:
							mBaseView.onFailure(TaskConstants.TASK_GOODSLIST);
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;
				case TaskConstants.INVERST_LIST://我的投资
					switch (adSlideBeen.code){
						case Constants.REQUESTCODE_000000:
							//请求成功，对数据进行解密
							try {
								String decode = AndroidDes3Util.decode(adSlideBeen.data, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0,24), (Date.parse(adSlideBeen.timestamp)+"").substring((Date.parse(adSlideBeen.timestamp)+"").length() - 8,(Date.parse(adSlideBeen.timestamp)+"").length()));
								String[] split = decode.split("\\n");
								ArrayList<MyInvestBeen> invests = GsonTool.jsonToArrayList(split[1], MyInvestBeen.class);
								//对数据进行解析
								if (event_tag == Constants.EVENT_REFRESH_DATA){
									//event_tag为刷新界面
									if (invests.size() > 0){
										mBaseView.refreshListData(invests);
									}else {
										mBaseView.refreshListData(null);
										//没有数据显示空页面
										mBaseView.showEmpty(0, mContext.getString(R.string.empty_msg), this);
									}
								} else if (event_tag == Constants.EVENT_LOAD_MORE_DATA){
									if (invests.size() > 0){
										mBaseView.addMoreListData(invests);
									}else {
										//没有更多

									}
								}
							}catch (Exception e){
								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
								e.printStackTrace();
							}

							break;
						case Constants.REQUESTCODE_100020:

							break;
						case Constants.REQUESTCODE_100010:
							break;
						case Constants.REQUESTCODE_100500:
							new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
							break;
						default:
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							mBaseView.showError(adSlideBeen.msg, this);
							break;
					}
					break;

				case TaskConstants.LOAN_LIST://我的借款
					switch (adSlideBeen.code){
						case Constants.REQUESTCODE_000000:
							//请求成功，对数据进行解密
							try {
								String decode = AndroidDes3Util.decode(adSlideBeen.data, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0,24), (Date.parse(adSlideBeen.timestamp)+"").substring((Date.parse(adSlideBeen.timestamp)+"").length() - 8,(Date.parse(adSlideBeen.timestamp)+"").length()));
								String[] split = decode.split("\\n");
								ArrayList<MyLoanListBeen> loanLists = GsonTool.jsonToArrayList(split[1],MyLoanListBeen.class);
								//对数据进行解析
								if (event_tag==Constants.EVENT_REFRESH_DATA){
									//event_tag为刷新界面
									if (loanLists.size() > 0){
										mBaseView.refreshListData(loanLists);
									}else {
										mBaseView.refreshListData(null);
										//没有数据显示空页面
										mBaseView.showEmpty(0, mContext.getString(R.string.empty_msg), this);
									}
								}
							} catch (Exception e) {
								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
								e.printStackTrace();
							}
							break;
						case Constants.REQUESTCODE_100500:
							new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
							mBaseView.showError(adSlideBeen.msg, this);
							break;
						case Constants.REQUESTCODE_100020:

							break;
						default:
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							mBaseView.showError(adSlideBeen.msg, this);
							break;
					}
					break;

				case TaskConstants.TASK_REPAYPLAN://还款计划
					switch (adSlideBeen.code){

						case Constants.REQUESTCODE_000000:
							try{
								String decode3 = AndroidDes3Util.decode(adSlideBeen.data, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0,24), (Date.parse(adSlideBeen.timestamp)+"").substring((Date.parse(adSlideBeen.timestamp)+"").length() - 8,(Date.parse(adSlideBeen.timestamp)+"").length()));
								String[] split3 = decode3.split("\\n");
								ArrayList<RepayPlanBeen> repayPlanBeens = GsonTool.jsonToArrayList(split3[1],RepayPlanBeen.class);
								Logs.e("TASK_REPAYPLAN:77777 " + split3[1]);
								if (repayPlanBeens.size() > 0){
									mBaseView.initializeViews(TaskConstants.TASK_REPAYPLAN,repayPlanBeens);
								}else {
									mBaseView.refreshListData(null);
									//没有数据显示空页面
									mBaseView.showEmpty(0, mContext.getString(R.string.empty_msg), this);
								}

								break;
							}catch(Exception e){
								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
								e.printStackTrace();
							}
						case Constants.REQUESTCODE_000001:
							mBaseView.initializeViews(TaskConstants.Task_FEE,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_000002:
							mBaseView.initializeViews(TaskConstants.Task_FEE,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_000003:
							mBaseView.initializeViews(TaskConstants.Task_FEE,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_000004:
							mBaseView.initializeViews(TaskConstants.Task_FEE,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_100500:
							new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
							break;
						case Constants.REQUESTCODE_100010:
							break;
						default:
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;

				case TaskConstants.TASK_REPAY://还款
					Log.e("DSFDFSDSFF",adSlideBeen.toString());
					switch (adSlideBeen.code){
						case Constants.REQUESTCODE_000000:
							//通知V层
							try {
								String decode = AndroidDes3Util.decode(adSlideBeen.data,sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0,24) ,(Date.parse(adSlideBeen.timestamp)+"").substring((Date.parse(adSlideBeen.timestamp)+"").length() - 8,(Date.parse(adSlideBeen.timestamp)+"").length()));
								String[] split = decode.split("\\n");
								Logs.e("TASK_REPAY:77777 " + decode);
								mBaseView.initializeViews(TaskConstants.TASK_REPAY,split[1]);
							} catch (Exception e) {
								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
								e.printStackTrace();
							}
							break;
						case Constants.REQUESTCODE_000001:
							mBaseView.initializeViews(TaskConstants.TASK_RETURN_MONEY,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_000002:
							mBaseView.initializeViews(TaskConstants.TASK_RETURN_MONEY,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_000003:
							mBaseView.initializeViews(TaskConstants.TASK_RETURN_MONEY,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_000004:
							mBaseView.initializeViews(TaskConstants.TASK_RETURN_MONEY,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_100500:
							new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
							break;
						case Constants.REQUESTCODE_100020:
							break;
						case Constants.REQUESTCODE_100010:
							break;
						default:
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;

				case TaskConstants.TASK_PREPAYPLAN://提前还款计划
					switch (adSlideBeen.code){
						case Constants.REQUESTCODE_000000:
							//通知V层
							try {
								String decode = AndroidDes3Util.decode(adSlideBeen.data,sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0,24) ,(Date.parse(adSlideBeen.timestamp)+"").substring((Date.parse(adSlideBeen.timestamp)+"").length() - 8,(Date.parse(adSlideBeen.timestamp)+"").length()));
								String[] split = decode.split("\\n");
								PrepayPlanBeen prepayPlanBeen = (PrepayPlanBeen) GsonTool.getInstanceByJson(PrepayPlanBeen.class, split[1]);
								mBaseView.initializeViews(TaskConstants.TASK_PREPAYPLAN,prepayPlanBeen);
							} catch (Exception e) {
								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
								e.printStackTrace();
							}
							break;
						case Constants.REQUESTCODE_100500:
							new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
							break;
						case Constants.REQUESTCODE_100020:
							break;
						case Constants.REQUESTCODE_100010:
							break;
						default:
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;

				case TaskConstants.TASK_PREPAY://提前还款 OK
					Logs.e("TASK_PREPAYPLAN:88888 " + adSlideBeen.toString());
					switch (adSlideBeen.code){
						case Constants.REQUESTCODE_000000:
							//通知V层
							try {
								String decode = AndroidDes3Util.decode(adSlideBeen.data,sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0,24) ,(Date.parse(adSlideBeen.timestamp)+"").substring((Date.parse(adSlideBeen.timestamp)+"").length() - 8,(Date.parse(adSlideBeen.timestamp)+"").length()));
								String[] split = decode.split("\\n");
								mBaseView.initializeViews(TaskConstants.TASK_PREPAY,split[1]);
							} catch (Exception e) {
								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
								e.printStackTrace();
							}
							break;
						case Constants.REQUESTCODE_000001:
							mBaseView.initializeViews(TaskConstants.Task_FEE,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_000002:
							mBaseView.initializeViews(TaskConstants.Task_FEE,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_000003:
							mBaseView.initializeViews(TaskConstants.Task_FEE,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_000004:
							mBaseView.initializeViews(TaskConstants.Task_FEE,adSlideBeen.msg);
							break;
						case Constants.REQUESTCODE_100500:
							new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_overdue)).show();
							break;
						case Constants.REQUESTCODE_100020:
							break;
						case Constants.REQUESTCODE_100010:
							break;
						default:
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;
				case TaskConstants.TASK_GETPRODTYPE:
					//项目类型
					switch (adSlideBeen.code) {
						case Constants.REQUESTCODE_000000:
							//对data进行解密
							try {
								String decode;
								if (sharedPreferences.getBoolean(UserInfo.ISLOGIN)){
									decode = AndroidDes3Util.decode(adSlideBeen.data, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
								} else {
									decode = AndroidDes3Util.decode(adSlideBeen.data, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
								}

								String[] split = decode.split("\\n");
								//解密成功，循环写入json数组中
								ArrayList<ProdTypeBean> prodTypeBean = GsonTool.jsonToArrayList(split[1], ProdTypeBean.class);
								//获取到been对象数组，通知view层
								this.mBaseView.initializeViews(task_name, prodTypeBean);
							} catch(Exception e){
								new HSToast(mContext).showToast(mContext.getString(R.string.date_error));
								mBaseView.showError(mContext.getString(R.string.network_anomaly), this);
								e.printStackTrace();
							}
							break;
						case Constants.REQUESTCODE_100600:
							mBaseView.showError(mContext.getString(R.string.login_overdue), this);
							sharedPreferences.putBoolean(UserInfo.ISLOGIN, false);
							mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
							EventBus.getDefault().post(new EventCenter(Constants.EVENT_DATA_LOGIN_EXPIRED));
							break;
						case Constants.REQUESTCODE_100010:
							mBaseView.showError(mContext.getString(R.string.network_anomaly), this);
							break;
						case Constants.REQUESTCODE_100020:
							mBaseView.showError(mContext.getString(R.string.network_anomaly), this);
							break;
						default:
							mBaseView.showError(mContext.getString(R.string.network_anomaly), this);
//							mBaseView.initializeViews(task_name, null);
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;

				case TaskConstants.TASK_MSGLIST:
					//消息列表
					switch (adSlideBeen.code) {
						case Constants.REQUESTCODE_000000:
							//对data进行解密
							try {
								String decode = AndroidDes3Util.decode(adSlideBeen.data, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
								String[] split = decode.split("\\n");
								//解密成功，循环写入json数组中
								ArrayList<MessageBean> messageBeens = GsonTool.jsonToArrayList(split[1], MessageBean.class);

								//获取到been对象数组，通知view层
								if (event_tag==Constants.EVENT_REFRESH_DATA){
									//event_tag为刷新界面
									if (messageBeens.size() > 0){
										mBaseView.refreshListData(messageBeens);
									} else {
										mBaseView.refreshListData(null);
										//没有数据显示空页面
										mBaseView.showEmpty(0, mContext.getString(R.string.empty_msg), this);
									}
								} else if (event_tag == Constants.EVENT_LOAD_MORE_DATA){
									if (messageBeens.size() > 0){
										mBaseView.addMoreListData(messageBeens);
									}else {
										//没有更多
										mBaseView.addMoreListData(messageBeens);
									}
								}


							} catch(Exception e){
								new HSToast(mContext).showToast(mContext.getString(R.string.date_error));
								mBaseView.showError(mContext.getString(R.string.network_anomaly), this);
								e.printStackTrace();
							}
							break;
						default:
							mBaseView.showError(mContext.getString(R.string.network_anomaly), this);
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;

				case TaskConstants.TASK_MSGREADALL:
					switch (adSlideBeen.code) {
						case Constants.REQUESTCODE_000000:
							//对data进行解密
							mBaseView.initializeViews(TaskConstants.TASK_MSGREADALL,"success");
							break;
						default:
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;
				//消息设置状态
				case TaskConstants.TASK_NOTICELIST:
					switch (adSlideBeen.code){

						case Constants.REQUESTCODE_000000:

							//通知V层
							try {
								String decode = AndroidDes3Util.decode(adSlideBeen.data,sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0,24) ,(Date.parse(adSlideBeen.timestamp)+"").substring((Date.parse(adSlideBeen.timestamp)+"").length() - 8,(Date.parse(adSlideBeen.timestamp)+"").length()));
								String[] split = decode.split("\\n");
								MessageSettingBean messageSettingBean = (MessageSettingBean) GsonTool.getInstanceByJson(MessageSettingBean.class, split[1]);
								mBaseView.initializeViews(TaskConstants.TASK_NOTICELIST,messageSettingBean);
							} catch (Exception e) {
								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error) + e.toString()).show();
								e.printStackTrace();
							}
							break;
						default:
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;

				case TaskConstants.TASK_MSGREADSET:
					switch (adSlideBeen.code){
						case Constants.REQUESTCODE_000000:
							//通知V层
							try {
								String decode = AndroidDes3Util.decode(adSlideBeen.data,sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0,24) ,(Date.parse(adSlideBeen.timestamp)+"").substring((Date.parse(adSlideBeen.timestamp)+"").length() - 8,(Date.parse(adSlideBeen.timestamp)+"").length()));

								mBaseView.initializeViews(task_name,adSlideBeen.code);
							} catch (Exception e) {
								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
								e.printStackTrace();
							}
							break;
						default:
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;

				case TaskConstants.TASK_LOGINSILENT:
					switch (adSlideBeen.code){
						case Constants.REQUESTCODE_000000:
							//通知V层
							try {
								String decode = AndroidDes3Util.decode(adSlideBeen.data,sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0,24) ,(Date.parse(adSlideBeen.timestamp)+"").substring((Date.parse(adSlideBeen.timestamp)+"").length() - 8,(Date.parse(adSlideBeen.timestamp)+"").length()));
								String[] split = decode.split("\\n");
								LoginBeen loginBeen = (LoginBeen) GsonTool.getInstanceByJson(LoginBeen.class,split[1]);
								mBaseView.initializeViews(TaskConstants.TASK_LOGINSILENT,loginBeen);

							} catch (Exception e) {
								mBaseView.onFailure(TaskConstants.TASK_LOGINSILENT);
								new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
								e.printStackTrace();
							}
							break;
						default:
							mBaseView.onFailure(TaskConstants.TASK_LOGINSILENT);
							new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
							break;
					}
					break;
			}
		} catch (Exception e){
			new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
			e.printStackTrace();
		}
	}

	/**
	 * 网络请求失败
	 * @param task_name
	 * @param msg
     */
	@Override
	public void onException(String task_name,String msg) {
		new HSToast(mContext).getSingleLongToast(msg).show();
		// TODO Auto-generated method stub
		mBaseView.closeProgress();
		mBaseView.hideLoading();
		if (!TextUtils.equals(task_name,TaskConstants.TASK_REPAY) && !TextUtils.equals(task_name,TaskConstants.TASK_PREPAYPLAN) && !TextUtils.equals(task_name,TaskConstants.TASK_PREPAY) && !TextUtils.equals(task_name,TaskConstants.TASK_GETPRODTYPE)){
			mBaseView.showError(msg, this);
		}

		mBaseView.onFailure(task_name);
	}

	
	@Override
	public void loadingData(String task_name, String url, int event_tag,
			HashMap<String, String> params, boolean isSwipeRefresh) {
		// TODO: 2017/5/4 这里应该通过不同的名字进行不同的网络请求
		if(event_tag==Constants.EVENT_REFRESH_DATA){
			this.mTask_name=task_name;
			this.mUrl=url;
			this.mParams=params;
			this.mIsSwipeRefresh=isSwipeRefresh;
			this.mEvent_tag=event_tag;
		}

        if(event_tag==Constants.EVENT_PROGRESS){
        	mBaseView.showProgress("");
		}
        if (isSwipeRefresh) {
        	mBaseView.showLoading(mContext.getString(R.string.common_loading_message));
        }
		if (NetUtils.isNetworkConnected(mContext)) {
			mInteractorGet.getRequestData(task_name, url, event_tag, params);
        }else{
			mBaseView.closeProgress();
        	mBaseView.hideLoading();
        	mBaseView.onFailure(task_name);
			//这边注册了点击事件，点击屏幕重新加载
        	mBaseView.showNetError(this);
        }
	}

	/**
	 * params+header请求产品信息
	 * @param task_name
	 * @param url
	 * @param event_tag
	 * @param params
	 * @param header
     * @param isSwipeRefresh
     */
	@Override
	public void loadingData(String task_name, String url, int event_tag, HashMap<String, String> params, HashMap<String, String> header, boolean isSwipeRefresh) {
		//header+params
		if(event_tag==Constants.EVENT_REFRESH_DATA){
			this.mTask_name=task_name;
			this.mUrl=url;
			this.mParams=params;
			this.mIsSwipeRefresh=isSwipeRefresh;
			this.mEvent_tag=event_tag;
			this.header = header;
		}

		if(event_tag==Constants.EVENT_PROGRESS){
			mBaseView.showProgress("");
		}
		if (isSwipeRefresh) {
			mBaseView.showLoading(mContext.getString(R.string.common_loading_message));
		}
		if (NetUtils.isNetworkConnected(mContext)) {
			mInteractorGet.getRequestData(task_name, url, event_tag, params,header);
		}else{
			mBaseView.closeProgress();
			mBaseView.hideLoading();
			mBaseView.onFailure(task_name);
			mBaseView.showNetError(this);
		}
	}

	//json+header
	@Override
	public void loadingData(String task_name, String url, int event_tag, JSONObject params, HashMap<String, String> header, boolean isSwipeRefresh) {
		if(event_tag==Constants.EVENT_REFRESH_DATA){
			this.mTask_name=task_name;
			this.mUrl=url;
			this.mJParams=params;
			this.mIsSwipeRefresh=isSwipeRefresh;
			this.mEvent_tag=event_tag;
			this.header = header;
		}

		if (NetUtils.isNetworkConnected(mContext)) {
			if (isSwipeRefresh) {
				mBaseView.showProgress("");
			}
				mInteractor.getRequestData(task_name, url, event_tag, params,header);
		}else{
			mBaseView.closeProgress();
			new HSToast(mContext).showToast(R.string.common_no_network);
//			mBaseView.initializeError(task_name,"");
		}
	}

	@Override
	public void initialized() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onClick(View v) {
		//加载失败的时候点击屏幕重新加载
		if (TextUtils.equals(TaskConstants.TASK_GOODSLIST,mTask_name)){
			zwgt_data = BaseRequestTool2.getFormatedDateString();
			loadingData(mTask_name, mUrl, mEvent_tag, mParams,header,mIsSwipeRefresh);
		} else if (TextUtils.equals(TaskConstants.TASK_GETPRODTYPE,mTask_name)){
			zwgt_data = BaseRequestTool2.getFormatedDateString();
			if (sharedPreferences.getBoolean(UserInfo.ISLOGIN)) {
				mParams = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test) + TaskConstants.TASK_GETPRODTYPE, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.
						getShareProf(UserInfo.TOKENID), zwgt_data);
			} else {
				mParams = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test) + TaskConstants.TASK_GETPRODTYPE, "", mConfigSP.
						getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);
			}

			loadingData(mTask_name, mUrl, mEvent_tag, mParams,mIsSwipeRefresh);
		} else if (TextUtils.equals(TaskConstants.TASK_MSGLIST,mTask_name)){
			zwgt_data = BaseRequestTool2.getFormatedDateString();
			loadingData(mTask_name, mUrl, mEvent_tag, mJParams,header ,mIsSwipeRefresh);
		}
	}
}
